//
//  SheetsBootcamp_29.swift
//  SwiftUiExercise
//
//  Created by 徐鹏 on 2023/7/2.
//

import SwiftUI

struct SheetsBootcamp_29: View {
    
    @State var showSheet : Bool = false
    
    var body: some View {
        ZStack{
            Color.green
                .edgesIgnoringSafeArea(.all)
            
            Button {
                
                showSheet.toggle()
                
            } label: {
                Text("Button")
                    .foregroundColor(.gray)
                    .font(.headline)
                    .padding(20)
                    .background(Color.white)
            }
            .fullScreenCover(isPresented: $showSheet) {
                SecondScreen()
            }
//            .sheet(isPresented: $showSheet) {
//                SecondScreen()
//            }

        }
        
    }
    
}

struct SecondScreen : View {
    
    @Environment(\.presentationMode) var presentationModel
    
    var body: some View{
        ZStack(alignment: .topLeading){
            Color.red
                .edgesIgnoringSafeArea(.all)
            
            Button {
                presentationModel.wrappedValue.dismiss()
               // showSheet.toggle()
                
            } label: {
                Image(systemName: "xmark")
                    .foregroundColor(.white)
                    .font(.headline)
                    .padding(20)
//                Text("Button")
//                    .foregroundColor(.red)
//                    .font(.headline)
//                    .padding(20)
//                    .background(Color.white)
            }
            
        }
    }
    
}

struct SheetsBootcamp_29_Previews: PreviewProvider {
    static var previews: some View {
        SheetsBootcamp_29()
    }
}
